package ca.cbc.gisdigester.daemon;

import ca.cbc.gisdigester.Main;
import org.quartz.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.text.SimpleDateFormat;
import java.util.Date;

@PersistJobDataAfterExecution
@DisallowConcurrentExecution
public class TweetSyncJob implements Job {

	private static Logger logger = LoggerFactory.getLogger(TweetSyncJob.class);
	private SimpleDateFormat durationFormat = new SimpleDateFormat("mm:ss");

	public TweetSyncJob() {
	}
	
	public void execute(JobExecutionContext context) throws JobExecutionException {
        // This job simply prints out its job name and the
        // date and time that it is running
        JobKey jobKey = context.getJobDetail().getKey();
        Date now = new Date();
        logger.info("^^^^^ Start executing {} at {} ^^^^^^", jobKey, now);
        Main.digestAndSaveTweets();
		logger.info("^^^^^ Done executing {}, duration is {} ^^^^^^^^^^^^^^^^^^^^", jobKey, durationFormat.format((new Date()).getTime() - now.getTime()));
	}
}
